package com.unionftech.common.common.adapter

import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.unionftech.common.R
import com.unionftech.common.R.color

class CountryFastIndexAdapter(list: MutableList<String>) :
    BaseQuickAdapter<String, BaseViewHolder>(
        R.layout.layout_country_char_index_item,
        list
    ) {
    private var selectIndex = 0
    override fun convert(holder: BaseViewHolder, item: String) {
        val position = holder.layoutPosition
        holder.setText(R.id.tv_fast_index, item)
        val textView = holder.getView<TextView>(R.id.tv_fast_index)
        if (position == selectIndex) {
            textView.setTextColor(context.getColor(color.color_7532FF))
        } else {
            textView.setTextColor(context.getColor(color.color_1C1D21_alpha60))
        }
    }

    fun setSelectIndex(index: Int) {
        if (index == -1 || index >= itemCount) {
            return
        }
        notifyItemChanged(selectIndex)
        selectIndex = index
        notifyItemChanged(selectIndex)
    }
}